@extends('admin.layout.main')
@section('content')
    <!-- iCheck for checkboxes and radio inputs -->
    <link rel="stylesheet" href="{{asset('/adminlte/plugins/iCheck/all.css')}}">
    <section class="content-header">
      <h1>
        红包列表
      </h1>
      <ol class="breadcrumb">
        <li><a href="javascript:void(0)"><i class="fa fa-dashboard"></i> 红包列表</a></li>
      </ol>
    </section>
    <section class="content">
        <!-- Small boxes (Stat box) -->
        <div class="row">
            <div class="col-lg-12 col-xs-6">
                <div class="box">
                    
                    <!-- /.box-header -->
                    <div class="box-body">
                        <table class="table table-bordered table-hover" id="user-list">
                            <div class="dataTables_filter">
                                <form action="" method="GET">
                                    <button type="submit" class="btn btn-info btn-sm">查询:</button>
                                    <button type="button" class="btn btn-default" id="daterange-btn">
                                        <span>
                                          <i class="fa fa-calendar"></i>
                                        </span>
                                        <i class="fa fa-caret-down"></i>
                                      </button>
                                    <input type="hidden" name="time">
                                </form>
                            </div>
                            <thead>
                                <tr>
                                    <th>用户</th>
                                    <th>金额</th>
                                    <th>发送时间</th>
                                    <th>提示信息</th>
                                    <th>发送状态</th>
                                    <th>错误描述</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody> 
                                @foreach($packets as $packet)
                                    <tr data-id="{{$packet->id}}">
                                        <td>@if($packet->user) @if($packet->user->headimg) <img style="width:18px" src="{{$packet->user->headimg}}"> @endif @if($packet->user->nickname) {{$packet->user->nickname}} @else {{base64_decode($packet->user->name)}} @endif @endif</td>
                                        <td>{{$packet->money}}</td>
                                        <td>{{$packet->created_at}}</td>
                                        <td>{!! str_limit($packet->message, 20, '...') !!}</td>
                                        <td>@if($packet->status == 1) <span style="color:#12bf11">发送成功</span> @else <span style="color:#ce0f31">发送失败</span> @endif</td>
                                        <td>{!! str_limit($packet->err_message, 20, '...') !!}</td>
                                        <td>
                                            <a href="javascript:void(0)" class="detail-packet"><i class="fa fa-eye"></i>详情</a>
                                            <a href="javascript:void(0)" class="remove-packet"><i class="fa fa-remove"></i>删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                            </tbody>
                        </table>
                        {{$packets->links()}}
                    </div>
                </div>
            </div>
        </div>
    </section>
    <!-- datepicker -->
    <script src="{{asset('/adminlte/plugins/datepicker/bootstrap-datepicker.js')}}"></script>
    <!-- iCheck 1.0.1 -->
    <script src="{{asset('/adminlte/plugins/iCheck/icheck.min.js')}}"></script>
    <script type="text/javascript">
        $(function () {
            // $('#user-list').DataTable({
            //   "paging": false,
            //   "lengthChange": false,
            //   "searching": false,
            //   "info": false,
            //   "autoWidth": true,
            //   "columns": [
            //     {"orderable": false},
            //     {"orderable": false},
            //     {"orderable": false},
            //     {"orderable": false},
            //     {"orderable": false},
            //     {"orderable": false},
            //     {"orderable": false},
            //   ]
            // });

            //Date range as a button
            $('#daterange-btn').daterangepicker(
                {
                  ranges: {
                    '今天': [moment(), moment().add(1, 'days')],
                    '昨天': [moment().subtract(1, 'days'), moment()],
                    '最近7天': [moment().subtract(6, 'days'), moment().add(1, 'days')],
                    '最近30天': [moment().subtract(29, 'days'), moment().add(1, 'days')],
                    '本月': [moment().startOf('month'), moment().endOf('month')],
                    '上月': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
                  },
                  startDate: moment().subtract(29, 'days'),
                  endDate: moment()
                },
                function (start, end) {
                  $('#daterange-btn span').html(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                  $("input[name = time]").val(start.format('YYYY-MM-DD') + ' ~ ' + end.format('YYYY-MM-DD'));
                }
            );
        });

        $('.all_check').click(function(){
            $('.checkbox_member').click();
        });

        $('.remove-packet').click(function(){
            var id = $(this).parents('tr').attr('data-id');
            bootbox.confirm({
                message: "确定删除这条红包记录吗?",
                buttons: {
                    confirm: {
                        label: '确定',
                        className: 'btn-success'
                    },
                    cancel: {
                        label: '取消',
                        className: 'btn-danger'
                    }
                },
                callback: function (result) {
                    if (result) {
                        window.location.href = '/admin/red_packet/remove/'+id;
                    }
                }
            });
        });

        $('.detail-packet').click(function(){
            var id = $(this).parents('tr').attr('data-id');
            dialog_group('/admin/red_packet/detail/'+id, '红包详情');
        });

    </script>
@endsection      